package com.personal.common.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtil {

	private static Logger log = Logger.getLogger(PropertiesUtil.class);

	//用户操作说明文件
	public static final String OPERATEFILEPATH = "operate.properties";

	//存放用户操作说明，键-值
	//键--类名.方法名
	//值--该方法描述
	private static Properties operateProperties = new Properties();

	/**
	 * 初始化文件
	 */
	static {
		loadPropertiesFile(PropertiesUtil.class.getResource("/").getPath() + OPERATEFILEPATH);
	}

	/**
	 * 加载properties文件
	 * @param filePath 文件路径
	 */
	public static void loadPropertiesFile(String filePath) {
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(filePath));
			operateProperties.load(in);
		} catch (FileNotFoundException e) {
			log.error("加载配置文件,路径为[" + filePath + "],该文件找不到！", e);
		} catch (IOException e) {
			log.error("读取配置文件发生IO异常，路径为[" + filePath + "]。", e);
		}
	}

	/**
	 * 根据key值获取操作说明文件对应的Value
	 * @param key
	 */
	public static String getOperateValue(String key) {
		String value = operateProperties.getProperty(key);
		return value;
	}
}
